package ig.formato.util;

import ig.formato.dto.CircularDTO;
import ig.formato.gui.run.PrincipalIGFormato;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Properties;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ListCellRender extends JLabel implements ListCellRenderer {

    public ListCellRender() {
        setOpaque(true);
        setBackground(Color.WHITE);        
    }

    public synchronized Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        ListCellRender lcr = new ListCellRender();
        CircularDTO cdto = ((CircularDTO) value);
        lcr.setText(cdto.getNombre());
        lcr.setBackground(isSelected ? new Color(216, 216, 252) : Color.WHITE);
        Properties properties = null;
        try {
            properties = LoadProperties.loadPropertiess("conf/color.properties");
        } catch (Exception e) {
        }
        if (properties != null) {
            try {
                lcr.setForeground(new Color(Integer.valueOf(properties.getProperty(cdto.getNombre()))));
                lcr.setFont(new Font(Font.DIALOG, Font.BOLD, 11));
            } catch (Exception e) {
                lcr.setForeground(Color.BLACK);
                lcr.setFont(new Font(Font.DIALOG, Font.PLAIN, 11));
            }
        }

        return lcr;
    }
//
//    boolean seleccionado=false;
//    public void paint( Graphics g ) {
//      Color color;
//      // Fijamos el colos de fondo
//      color = seleccionado ? new Color(216,216,252) : Color.white;
//      g.setColor( color );
//      g.fillRect( 0,0,getWidth()-1,getHeight()-1 );
//      super.paint( g );
//    }
}
